﻿import { Cart, Order, Checkout } from "../domain/model";
import { DataContextFactory } from "../domain/fbsDataContext";
import { OrderStatusEnum, PaymentsStatusEnum } from "../domain/model/orderStatusEnum";
import { ServiceException } from "./serviceException";
import { Guid, Logger } from "../common";

export class WeChatOrderService {
    ctx = DataContextFactory.GetDataContext();
    private accessLogger;
    constructor() {
        this.accessLogger = new Logger().getLogger('access');
    }
    /**
    * 快餐版下单
    * @param  {} orders 订单对象
    */
    async FastOrdering(orders) {
        let currentOrder: Order = new Order();
        let order: Order = new Order();
        let amountDue: number = 0, remainAmount: number = 0, orderNo: string;
        let result: any = {};

        // 订单号
        orderNo = orders.orderNo;

        for (let i = 0, orderLen = orders.cart.items; i < orderLen; i++) {
            if (!order.cart.items[i].inventoryCode) throw new ServiceException(this, "订单入库失败，购物车商品无编码！");
        }

        // 计算总价格
        try {
            amountDue = (orders.amountDue == undefined || orders.amountDue == null) ? 0 : orders.amountDue;
            orders.cart.items.forEach((item) => {
                remainAmount += (!isNaN(Number(item.amount))) ? (Number(item.amount)) : 0;
                item.id = Guid.GetGuid();
            })

            // 新生成订单数据结构
            currentOrder.amountDue = order.amountDue = amountDue;
            currentOrder.cart = order.cart = orders.cart ? orders.cart : {};
            currentOrder.createTime = order.createTime = new Date().getTime();
            currentOrder.creator = order.creator = orders.creator;
            currentOrder.creatorId = order.creatorId = orders.creatorId;
            currentOrder.discount = order.discount = orders.discount ? orders.discount : 0;
            currentOrder.discounts = order.discounts = orders.discounts ? orders.discounts : [];
            currentOrder.description = order.description = orders.description ? orders.description : null;
            currentOrder.extended = order.extended = orders.extended ? orders.extended : {};
            currentOrder.id = order.id = orderNo;
            currentOrder.member = orders.member ? orders.member : null;
            currentOrder.memberType = orders.memberType ? orders.memberType : null;
            currentOrder.orderDiscount = order.orderDiscount = orders.orderDiscount ? orders.orderDiscount : 0;
            currentOrder.orderNo = order.orderNo = orderNo;
            currentOrder.orderType = order.orderType = "sales";
            currentOrder.paidAmount = order.paidAmount = orders.paidAmount ? orders.paidAmount : 0;
            currentOrder.payments = []; // 原数据结构冗余字段
            currentOrder.remainAmount = order.remainAmount = remainAmount;	// 暂无折扣直接用remainAmount
            currentOrder.serialNo = order.serialNo = orders.serialNo;       // 流水号
            currentOrder.smallChangeOff = order.smallChangeOff = !isNaN(orders.smallChangeOff) ? orders.smallChangeOff : 0;
            currentOrder.status = order.status = OrderStatusEnum[OrderStatusEnum.ordered];   // 枚举订单状态
            currentOrder.storeId = order.storeId = orders.storeId;
            currentOrder.subtotal = order.subtotal = remainAmount;      // 暂无折扣直接用remainAmount
            currentOrder.terminalName = order.terminalName = orders.terminalName ? orders.terminalName : null;
            currentOrder.sourceid = order.sourceid = orders.sourceid;
            currentOrder.openid = order.openid = orders.openid;
        } catch (error) {
            throw new ServiceException(this, "订单入库失败！" + error);
        }

        // 订单信息入库
        try {
            result = await this.ctx.Create(currentOrder);
            // 屏蔽数据结构多余字段
            if ((<any>order).sqlTemp) delete (<any>order).sqlTemp;
            if ((<any>order).queryParam) delete (<any>order).queryParam;
            if (result) return order;
        } catch (error) {
            this.accessLogger.info("订单入库失败！ %s" + error);
            throw new ServiceException(this, "订单入库失败！" + error);
        }
    }

    /**
     * 微信快餐结算
     * @param  {} orders 订单对象
     */
    async Checkout(orders) {
        let order: Order, checkout: Checkout = new Checkout(), amountDue: number = 0;
        if (!orders.orderNo) throw new ServiceException(this, "订单号有误，结算失败！");

        order = await this.GetOrderById(orders.orderNo);
        if (order == undefined) throw new ServiceException(this, "结算失败，无该订单信息！");
        if (order.status != "ordered" && order.status != "settled") throw new ServiceException(this, "结算失败，订单状态有误！");

        try {
            amountDue = (order.amountDue == undefined || order.amountDue == null) ? 0 : order.amountDue;
            checkout.id = Guid.GetGuid();
            checkout.amountDue = amountDue;
            checkout.remainAmount = order.remainAmount;
            checkout.storeId = order.storeId;
            checkout.terminalName = order.terminalName;
            checkout.createTime = new Date().getTime();

            order.checkout = checkout;
            order.status = OrderStatusEnum[OrderStatusEnum.settled];   // 枚举订单状态
            // 更新订单信息
            let result = await this.ctx.Update(order);
            // 屏蔽数据结构多余字段
            if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
            if ((<any>result).queryParam) delete (<any>result).queryParam;
            if (result) return result;
        } catch (error) {
            console.log("--------------------------------结算失败--------------------------------");
            console.log(error);
            this.accessLogger.info("结算失败 %s" + error);
            throw new ServiceException(this, "结算失败！");
        }
    }

    /**
     * 支付完成更新订单状态（微信快餐版）
     * @param  {} orders 订单对象
     */
    async GeneratePay(orders) {
        let order: Order, checkout: Checkout = new Checkout(), amountDue: number = 0;
        let payments: any = {};
        if (!orders.orderNo) throw new ServiceException(this, "订单号有误，结算失败！");

        order = await this.GetOrderById(orders.orderNo);
        if (order == undefined) throw new ServiceException(this, "生成预支付信息失败，无该订单信息！");

        payments.id = Guid.GetGuid();
        payments.amount = order.remainAmount;
        payments.channel = orders.channel;
        payments.channelId = orders.channelId;
        payments.createTime = new Date().getTime();
        payments.payMode = "pay";
        payments.storeId = order.storeId;
        payments.orderNo = order.orderNo;
        payments.status = PaymentsStatusEnum[PaymentsStatusEnum.paying];    // 枚举支付状态

        if (order.checkout == null || order.checkout == undefined) throw new ServiceException(this, "生成预支付信息失败，无结算信息！");
        order.checkout.payments = Array.of(payments);

        // 订单信息入库
        try {
            let result = await this.ctx.Update(order);
            // 屏蔽数据结构多余字段
            if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
            if ((<any>result).queryParam) delete (<any>result).queryParam;
            if (result) return result;
        } catch (error) {
            console.log("--------------------------------生成预支付信息失败--------------------------------")
            console.log(error);
            this.accessLogger.info("生成预支付信息失败 %s" + error);
            throw new ServiceException(this, "生成预支付信息失败！");
        }
    }

    /**
     * 支付完成更新订单状态（微信快餐版）
     * @param  {} orders 订单对象
     */
    async CompletePay(order) {
        let currentOrder = await this.GetOrderById(order.orderNo);
        let processStatus: any = {}, detail: any = {};
        let payments: any = {};
        let paramPayments = order.payments[order.payments.length - 1];

        this.CheckOrder(currentOrder);
        if (currentOrder.status != "settled") throw new ServiceException(this, "更新订单支付状态失败，订单状态有误！");
        payments = currentOrder.checkout.payments[currentOrder.checkout.payments.length - 1];
        this.CheckOrderPayments(payments, paramPayments);

        for (let i = 0, pLen = currentOrder.checkout.payments.length; i < pLen; i++) {
            currentOrder.checkout.payments[i].storeId = currentOrder.storeId;
        }

        payments.received = paramPayments.received;
        if (payments.status != PaymentsStatusEnum[PaymentsStatusEnum.paying]) throw new ServiceException(this, "更新订单支付状态失败，该订单支付状态有误！");
        payments.status = PaymentsStatusEnum[PaymentsStatusEnum.paid];   // 枚举支付状态

        currentOrder.amountDue = order.amountDue;
        currentOrder.status = OrderStatusEnum[OrderStatusEnum.closed];   // 枚举订单状态
        currentOrder.checkout.amountDue = order.amountDue;
        currentOrder.checkout.paidAmount = order.amountDue;
        currentOrder.checkout.payState = "paid";
        currentOrder.checkout.closeTime = new Date().getTime();
        currentOrder.closeTime = new Date().getTime();

        // 生成消息数据
        processStatus.id = Guid.GetGuid();
        processStatus.orderNo = detail.orderNo = order.orderNo;
        processStatus.statusType = detail.statusType = order.statusType;
        processStatus.status = detail.status = "noticed";

        detail.id = Guid.GetGuid();
        detail.createTime = new Date().getTime();

        processStatus.detail = [];
        processStatus.detail.push(detail);
        currentOrder.processStatus = processStatus;
        // 订单信息入库
        let result = await this.ctx.Update(currentOrder);
        // 屏蔽数据结构多余字段
        if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
        if ((<any>result).queryParam) delete (<any>result).queryParam;
        if (result) return result;
    }

    /**
     * 微信点单快餐版订单检测
     * @param  {} order
     */
    private CheckOrder(order) {
        if (!order) throw new ServiceException(this, "更新订单状态失败，无订单信息！");
        if (!order.status) throw new ServiceException(this, "更新订单状态失败，订单状态有误！");
        if (!order.cart) throw new ServiceException(this, "更新订单状态失败，无购物车信息！");
        if (!order.cart.items) throw new ServiceException(this, "更新订单状态失败，购物车无商品！");
        if (!order.checkout) throw new ServiceException(this, "更新订单状态失败，该订单无结算信息！");
        if (!order.checkout.payments) throw new ServiceException(this, "更新订单状态失败，订单结算支付信息有误！");
        if (order.cart.items.length <= 0) throw new ServiceException(this, "退单失败，购物车无商品！");
    }

    /**
     * 微信点单快餐版订单支付信息检测
     * @param  {} payments 订单支付信息
     * @param  {} paramPayments 传入支付信息
     */
    private CheckOrderPayments(payments, paramPayments) {
        if (!payments) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付信息！");
        if (!payments.id) throw new ServiceException(this, "更新订单支付状态失败，支付ID有误！");
        if (!payments.amount || payments.amount != Math.abs(paramPayments.amount)) throw new ServiceException(this, "更新订单支付状态失败，支付金额有误！");
        if (!payments.channel) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付方式！");
        if (!payments.channelId) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付类型ID！");
        if (!payments.createTime) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付时间信息！");
        if (!payments.payMode) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付模式信息！");
        if (!paramPayments.received) throw new ServiceException(this, "更新订单支付状态失败，实收金额有误！");
        if (!payments.storeId) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付店铺ID信息！");
        if (!payments.orderNo) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付订单号信息！");
        if (!payments.status) throw new ServiceException(this, "更新订单支付状态失败，该订单无支付状态信息！");
    }

    /**
     * 支付完成更新订单状态（微信快餐版）
     * @param  {} orders 订单对象
     */
    async CloseOrder(order) {
        let processStatus: any = {};

        if (!order) throw new ServiceException(this, "设置订单消息状态失败！");
        let currentOrder = await this.GetOrderById(order.orderNo);

        if (!currentOrder) throw new ServiceException(this, "更新订单完成状态失败，无此订单信息！");
        if (!currentOrder.status || currentOrder.status != "closed") throw new ServiceException(this, "更新订单完成状态失败，订单状态有误！");
        if (!currentOrder.processStatus) throw new ServiceException(this, "更新订单完成状态失败，订单消息为空！");

        // 判断订单消息状态是否为最终状态
        let detailLast = currentOrder.processStatus.detail.length - 1;
        let status = currentOrder.processStatus.detail[detailLast].status;
        if (status != "noticed") throw new ServiceException(this, "更新订单完成状态失败，该订单状态无法更改！");

        // 订单消息状态
        processStatus.id = Guid.GetGuid();
        processStatus.orderNo = order.orderNo;
        processStatus.statusType = currentOrder.processStatus.statusType;
        processStatus.status = "received";
        processStatus.createTime = new Date().getTime();

        currentOrder.processStatus.detail.push(processStatus);
        currentOrder.lastPrintTime = order.lastPrintTime;
        currentOrder.processStatus.status = "received";

        // 订单信息入库
        let result = await this.ctx.Update(currentOrder);
        // 屏蔽数据结构多余字段
        if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
        if ((<any>result).queryParam) delete (<any>result).queryParam;
        if (result) return result;

    }

    /**
     * 退单（微信快餐版）
     * @param  {} refundOrder 订单对象
     */
    async RefundOrder(refundOrder) {
        let refArr: any = [], result: any = {};
        let order = await this.refundOrderBefore(refundOrder);

        // 原单结算信息
        if (!order.checkout.refOrderId || !Array.isArray(order.checkout.refOrderId)) order.checkout.refOrderId = [];

        // 原单结算refOrderId指向原单本身
        order.checkout.refOrderId = Array.of({
            id: order.orderNo,
            type: "checkout"
        });

        // 生成新退单Id
        refArr.push({
            id: Guid.GetGuid(),
            type: "refund"
        });

        order.refOrderId = refArr;

        try {
            // 订单信息入库
            let original = await this.ctx.Update(order);
            let refundOrder = await this.CreateRefundOrder(order);
            result.original = original;
            result.refundOrder = new Order().clone(refundOrder, new Order());
            if (original && refundOrder) return result;
        } catch (error) {
            console.log("-------------------------------- 退单失败！--------------------------------");
            console.log(error);
            this.accessLogger.info("退单失败！ %s" + error);
            throw new ServiceException(this, "退单失败！");
        }
    }

    /**
     * 订单改为退单状态
     * @param  {} order 退单信息
     */
    private async refundOrderBefore(refundOrder) {
        let refundAmount = refundOrder.refundAmount;
        if (!Array.isArray(refundOrder.payments) || refundOrder.payments.length <= 0) throw new ServiceException(this, "退单失败，无支付信息！");
        let paramPayments = refundOrder.payments[refundOrder.payments.length - 1];

        if (!refundOrder.orderNo) throw new ServiceException(this, "退单失败，订单号有误！");
        if (!refundAmount || refundAmount > 0) throw new ServiceException(this, "退单失败，退款金额有误！");
        if (!refundOrder.serialNo) throw new ServiceException(this, "退单失败，退款流水号有误！");

        let order = await this.GetOrderById(refundOrder.orderNo);
        this.CheckOrder(order);
        if (order.status == "refund") throw new ServiceException(this, "退单失败，不能重复退单！");

        let payments = order.checkout.payments;
        let currentPaymentIndex = payments.length - 1;
        this.CheckOrderPayments(payments[currentPaymentIndex], paramPayments);
        // 原单状态信息
        order.refundAmount = refundAmount;
        order.refundCause = refundOrder.refundCause ? refundOrder.refundCause : "";
        order.status = OrderStatusEnum[OrderStatusEnum.refund];   // 枚举订单状态
        return order;
    }

    /**
     * 生成新订单(退单)
     * @param  {} order 原单
     */
    private async CreateRefundOrder(order) {
        let refundOrder: Order = new Order();
        let refOrderId: any = {}, refundAmount: number = 0, orderNo: string;
        let result: any = {}, ids: any = [];

        // 校验退款金额
        if (order.refundAmount && order.refundAmount != undefined) {
            refundAmount = order.refundAmount;
        } else {
            return null;
        }

        if (!isNaN(Number(refundAmount))) {
            refundAmount = (Number(refundAmount));
        } else {
            return null;
        }

        ids = JSON.parse(JSON.stringify(order.refOrderId));

        // 订单号
        orderNo = ids[ids.length - 1].id;

        // 原单与退单关联
        refOrderId.id = order.id;
        refOrderId.type = "sales";

        // 生成新退单支付信息
        let payments = order.checkout.payments;
        let currentPaymentIndex = payments.length - 1;
        payments[currentPaymentIndex].id = Guid.GetGuid();
        payments[currentPaymentIndex].orderNo = orderNo;
        payments[currentPaymentIndex].amount = -(payments[currentPaymentIndex].amount);
        payments[currentPaymentIndex].received = -(payments[currentPaymentIndex].received);

        // 退单结算信息
        refundOrder.checkout = JSON.parse(JSON.stringify(order.checkout));
        refundOrder.checkout.id = Guid.GetGuid();
        refundOrder.checkout.amountDue = refundAmount;
        refundOrder.checkout.paidAmount = refundAmount;
        refundOrder.checkout.payments = payments;
        refundOrder.checkout.createTime = payments[0].createTime;
        refundOrder.checkout.closeTime = new Date().getTime();
        // 退单结算refOrderId指向原单本身
        refundOrder.checkout.refOrderId = Array.of({
            id: orderNo,
            type: "checkout"
        });

        // 新生成退单数据结构
        refundOrder.amountDue = refundAmount;
        try {
            refundOrder.cart = JSON.parse(JSON.stringify(order.cart));
            refundOrder.cart.items.forEach((item) => {
                item.id = Guid.GetGuid();
                item.qty = -item.qty;
                item.amount = -item.amount;
            })
        } catch (error) {
            throw new ServiceException(this, "退单失败，购物车商品信息有误！");
        }
        (<any>refundOrder).masterOrder = order.masterOrder ? order.masterOrder : null;
        refundOrder.createTime = new Date().getTime();
        refundOrder.creator = order.creator;
        refundOrder.creatorId = order.creatorId;
        refundOrder.discount = 0;
        refundOrder.discounts = order.discounts ? order.discounts : [];
        refundOrder.extended = order.extended ? order.extended : {};
        refundOrder.id = orderNo;
        refundOrder.member = order.member ? order.member : null;
        refundOrder.memberType = order.memberType ? order.memberType : null;
        refundOrder.orderDiscount = order.orderDiscount ? order.orderDiscount : 0;
        refundOrder.orderNo = orderNo;
        refundOrder.orderType = "refund";   // 销售类型
        refundOrder.paidAmount = refundAmount;
        refundOrder.payments = [];  // 原数据结构冗余字段
        refundOrder.remainAmount = refundAmount;
        refundOrder.serialNo = order.serialNo;   // 流水号
        refundOrder.smallChangeOff = 0;
        refundOrder.status = OrderStatusEnum[OrderStatusEnum.closed];   // 枚举订单状态
        refundOrder.storeId = order.storeId;
        refundOrder.subtotal = refundAmount;      // 暂无折扣直接用refundAmount
        refundOrder.terminalName = order.terminalName ? order.terminalName : null;
        refundOrder.refOrderId = Array.of(refOrderId);
        refundOrder.closeTime = new Date().getTime();
        refundOrder.sourceid = order.sourceid;

        // 订单信息入库
        result = await this.ctx.Create(refundOrder);
        // 屏蔽数据结构多余字段
        if ((<any>refundOrder).sqlTemp) delete (<any>refundOrder).sqlTemp;
        if ((<any>refundOrder).queryParam) delete (<any>refundOrder).queryParam;
        if (result) return result;

    }

    /**
     * 查询单条订单信息
     * @param  {string} orderId 订单Id
     */
    async GetOrderById(orderNo: string) {
        let result: any = {};
        try {
            result = await this.ctx.Order.First(x => x.orderNo == orderNo, ["orderNo"], [orderNo]);
            if (result) return result;
        } catch (error) {
            this.accessLogger.info("订单查询失败！ %s" + error);
            throw new ServiceException(this, "订单查询失败！" + error);
        }
    }

    /**
     * 查询多条订单信息
     * @param  {string} orderIds 订单Ids
     */
    async GetOrderByIds(orderIds: any) {
        let result: any = {};
        try {
            result = await this.ctx.Order.Contains(x => x.id, orderIds).ToList();
            if (result && result.length > 0) {
                result.forEach((item) => {
                    if ((<any>item).sqlTemp) delete (<any>item).sqlTemp;
                    if ((<any>item).queryParam) delete (<any>item).queryParam;
                })
                return result;
            }
        } catch (error) {
            this.accessLogger.info("订单查询失败！ %s" + error);
            throw new ServiceException(this, "订单查询失败！" + error);
        }
    }

    /**
     * 查询单条订单信息
     * @param  {string} orderId 订单Id
     */
    async GetOrder(param: OrderQueryParameter) {
        let result: any = {};
        try {
            if (param) {
                if (param.openid) {
                    this.ctx.Order.Where(x => x.openid == param.openid, ["param.openid"], [param.openid]);
                }
                if (param.storeId) {
                    this.ctx.Order.Where(x => x.storeId == param.storeId, ["param.storeId"], [param.storeId]);
                }
                if (param.startTime) {
                    this.ctx.Order.Where(x => x.createTime >= param.startTime, ["param.startTime"], [param.startTime]);
                }
                if (param.endTime) {
                    this.ctx.Order.Where(x => x.createTime <= param.endTime, ["param.endTime"], [param.endTime]);
                }
                if (param.orderStatus && param.orderStatus.length > 0) {
                    this.ctx.Order.Contains(x => x.status, param.orderStatus);
                }
            }
            return this.ctx.Order.ToList();
        }
        catch (error) {
            this.accessLogger.info("订单查询失败！ %s" + error);
            throw new ServiceException(this, "订单查询失败！" + error);
        }
    }

    /**
     * 取消订单（微信快餐版）
     * @param  {} orders 订单对象
     */
    async CancelOrder(order) {
        if (!order) throw new ServiceException(this, "设置订单状态失败！");
        let currentOrder = await this.GetOrderById(order.orderNo);

        if (!currentOrder) throw new ServiceException(this, "更新订单取消状态失败，无此订单信息！");
        if (!currentOrder.checkout || !currentOrder.checkout.payments) throw new ServiceException(this, "更新订单取消状态失败，该订单无支付信息！");

        if (currentOrder.status == "cancer") throw new ServiceException(this, "取消订单失败，该订单为取消状态！");
        if (currentOrder.status == "closed") throw new ServiceException(this, "取消订单失败，该订单为结算状态！");
        if (currentOrder.status == "refund") throw new ServiceException(this, "取消订单失败，该订单为退单状态！");

        currentOrder.status = OrderStatusEnum[OrderStatusEnum.cancel];   // 枚举订单状态
        currentOrder.checkout.payments[currentOrder.checkout.payments.length - 1].status = PaymentsStatusEnum[PaymentsStatusEnum.cancelled];   // 枚举支付状态

        // 订单信息入库
        let result = await this.ctx.Update(currentOrder);
        // 屏蔽数据结构多余字段
        if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
        if ((<any>result).queryParam) delete (<any>result).queryParam;
        if (result) return result;
    }

    /**
     * 更新订单通知失败状态（微信快餐版）
     * @param  {} orders 订单对象
     */
    async NotifyFailed(order) {
        let processStatus: any = {};

        if (!order) throw new ServiceException(this, "设置订单消息状态失败！");
        let currentOrder = await this.GetOrderById(order.orderNo);

        if (!currentOrder) throw new ServiceException(this, "更新订单完成状态失败，无此订单信息！");
        if (!currentOrder.status || currentOrder.status != "closed") throw new ServiceException(this, "更新订单完成状态失败，订单状态有误！");
        if (!currentOrder.processStatus) throw new ServiceException(this, "更新订单完成状态失败，订单消息为空！");

        // 判断订单消息状态是否为最终状态
        let detailLast = currentOrder.processStatus.detail.length - 1;
        let status = currentOrder.processStatus.detail[detailLast].status;
        if (status != "noticed") throw new ServiceException(this, "更新订单完成状态失败，该订单状态无法更改！");

        // 订单消息状态
        processStatus.id = Guid.GetGuid();
        processStatus.orderNo = order.orderNo;
        processStatus.statusType = currentOrder.processStatus.statusType;
        processStatus.status = "failed";
        processStatus.createTime = new Date().getTime();

        currentOrder.processStatus.detail.push(processStatus);
        currentOrder.lastPrintTime = order.lastPrintTime;
        currentOrder.processStatus.status = "failed";

        // 订单信息入库
        let result = await this.ctx.Update(currentOrder);
        // 屏蔽数据结构多余字段
        if ((<any>result).sqlTemp) delete (<any>result).sqlTemp;
        if ((<any>result).queryParam) delete (<any>result).queryParam;
        if (result) return result;
    }
}

export interface OrderQueryParameter {
    openid?: string;
    storeId?: string;
    startTime?: number;
    endTime?: number;
    orderStatus?: string[];

}